﻿using System;
using System.Web;
using System.Web.Security;
using Cms.Domain;
using Cms.Web.Framework.Infrastructure.Wrappers;

namespace Cms.Web.Framework.Infrastructure
{
    public class UrlRewriter : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
        }

        public void Init(HttpApplication application)
        {
            application.AuthorizeRequest += AuthorizeRequest;
        }

        #endregion

        protected void AuthorizeRequest(object sender, EventArgs e)
        {
            // Instantiate UrlRewriter with sharp versions of all wrappers
            UrlRewriterHandler urlRewriter = new UrlRewriterHandler(
                (RequestDetails)HttpContext.Current.Items["RequestDetails"],
                new CmsHttpContext(), 
                new CmsFormsAuthentication(), 
                new CmsHttpContextItems(), 
                new CmsIdentity(),
                new CmsCache());
            urlRewriter.AuthorizeRequest();
        }
    }
}